##################################################################

# Gautam Nair
# gautam.nair@yale.edu
# Misperceptions of Relative Affluence and Support for International Transfers
# Make Table 13: Attitudes Towards Domestic Redistribution

##################################################################

# setwd("")

##################################################################
# loading packages
##################################################################

library(Hmisc)
library(foreign)
library(sandwich)
library(lmtest)
library(numDeriv)
library(stargazer)
library(ggplot2)
library(plyr)
library(gridExtra)
library(ri)
library(dplyr)
library(plyr)
library(scales)

##################################################################

rm(list=ls())

data.working <- readRDS("d_r_cleaned_analysis_dataset.Rda")

reg.model.1 <- lm(q10 ~group3+group2, data = data.working, na.omit=TRUE)
robust.se.1  <- sqrt(diag(vcovHC(reg.model.1, type = "HC")))

data.subset <- data.working[data.working$group2==1 | data.working$group3==1,] 
tresults.1 <- round((t.test(q10~group3, data=data.subset, alternative = c("less"))$p.value), digits=2)
lines.add <- c("Information-Salience (p-val.)", tresults.1)

varlabels <-       c("Information", "Salience", "Constant (Control Group Mean)" )
spectitle <- c("Support for Domestic Redistribution")
outputfile <- c("tf_t_13_domestic_redistribution.txt")
columnlabels <-c("Support for Domestic Redistribution (Ordinal 1-7)")
# depvarcaption <- c("Support for Domestic Redistribution ")
cutoffs.star <- c(0.05, 0.01)
char.star = c("**", "***")

stargazer(reg.model.1, 
          se=list(robust.se.1),
         title= spectitle,
          out=outputfile,
          type="text",
          no.space=TRUE, 
          model.numbers= TRUE,
         notes.append=FALSE,
          align=FALSE,
         covariate.labels=varlabels,
          header= FALSE,
          font.size="small",
          model.names=TRUE,
          digits=2,
          omit.stat = c("rsq", "f","adj.rsq"),
          column.labels  = columnlabels,
          dep.var.caption  = "",
          dep.var.labels.include=FALSE,
         df=FALSE,
         omit.table.layout="n",
                  star.cutoffs = cutoffs.star,
     star.char = char.star,
         add.lines =lines.add
) 
